/*
 * @describe: ***
 * @version: 1.0
 * @Author: yanghm
 * @Date: 2023-04-10 09:30:31
 * @LastEditors: yanghm
 * @LastEditTime: 2023-04-14 10:17:58
 */
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import store from '@/store/index.js'

Vue.use(Router)

const router = new Router({
  mode: 'hash',
  routes: [
    {
        path: '/',
        redirect: 'login'
      },
      {
        path: '/login',
        name: 'login',
        component: () =>
          import('@/view/login/index')
      },
      {
        path: '/home',
        name: 'home',
        // meta: {
        //   requireAuth: true
        // },
        component: () =>
          import('@/view/home/index')
      },
      {
        path: '/',
        name: 'HelloWorld',
        component: HelloWorld
      }
  ]
})
// 路由跳转前
router.beforeEach((to, from, next) => {
  if(to.path === '/login') return next()
  if(!localStorage.token) return next('/login')
  next()
})
// 路由跳转后
router.afterEach(route => {
  window.scrollTo(0, 0) // 跳转后返回页面顶部
})

export default router
